package com.jmyd.sharding.server.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author samphin
 * @since 2021/1/12 11:14
 */
@Configuration
public class CorsConfig implements WebMvcConfigurer {

    private static final String[] ORIGINS = new String[]{"GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"};

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowCredentials(true)
                .allowedMethods(ORIGINS)
                .maxAge(3600);
    }

}
